home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / AOCE / Development Tools / Sample Code / Standard Catalog Package / DTS AddressOMatic / Src / AOMSetButtonText.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-17  |  5.8 KB  |  209 lines  |  [TEXT/KAHL]

  1. /*                                AOMSetButtonText.c                                */
  2. /*
  3.  * AddressOMatic Sample
  4.  * AOMSetButtonText.c
  5.  * Copyright © 1993 Apple Computer Inc. All rights reserved.
  6.  */
  7. #include "AddressOMaticPrivate.h"
  8.  
  9. /*
  10.  * This is called whenever the button state changes. See AddressOMatic.h
  11.  * for a description of the button text strings how they are computed.
  12.  */
  13. void
  14. _AOMSetButtonText(
  15.         register AddressOMaticPtr    aomPtr
  16.     )
  17. {
  18.         short                        toStringIndex;
  19.         short                        ccStringIndex;
  20.         OSErr                        status;
  21.         SDPSelectionState            selectionState;
  22.         SDPFindPanelState            findState;
  23.         SDPPanelHandle                thePanel;
  24.         Boolean                        enableToButton;
  25.         Boolean                        enableCCButton;
  26.         AOMSaveState                saveState;
  27.         Str255                        title;
  28.  
  29.         _AOMSaveState(aomPtr, kAOMLabelFontStyle, &saveState);
  30.         enableToButton = FALSE;
  31.         enableCCButton = FALSE;
  32.         if (AOM.toButton != NULL || AOM.ccButton != NULL) {
  33.             /*
  34.              * If we don't know any better, set the "to"
  35.              * button to its current value, and set the
  36.              * "cc" button to either "cc" or "bcc" depending
  37.              * on the state of the option key.
  38.              */
  39.             toStringIndex = AOM.toButtonString;
  40.             ccStringIndex =
  41.                 (AOM.optKeyDown == 0)
  42.                     ? kAOMCCButtonString
  43.                     : kAOMOptCCButtonString;
  44.             switch (AOM.currentMode) {
  45.             case kAOMEnablePDBit:
  46.                 thePanel = AOM.pdPanel;
  47.                 goto setPanel;
  48.             case kAOMEnablePanelBit:
  49.                 thePanel = AOM.browsePanel;
  50. setPanel:        /*
  51.                  * The browse panel lets the user examine catalogs and select
  52.                  * records. Also,  records and containers may be saved into
  53.                  * the user's personal directory.
  54.                  */
  55.                 status = SDPGetPanelSelectionState(thePanel, &selectionState);
  56.                 if (status == noErr) {
  57.                     switch (selectionState) {
  58.                     default:
  59.                     case kSDPNothingSelected:
  60.                         /*
  61.                          * If nothing is selected, leave the button
  62.                          * texts alone, but disable both buttons.
  63.                          */
  64.                         break;
  65.                     case kSDPLockedContainerSelected:
  66.                         /*
  67.                          * A locked container is visible, but cannot
  68.                          * be opened. Set the "to" button string
  69.                          * to "Open" but leave it disabled. The "cc"
  70.                          * button is likewise disabled.
  71.                          */
  72.                         toStringIndex = kAOMOpenButtonString;
  73.                         break;
  74.                     case kSDPContainerAliasSelected:
  75.                     case kSDPContainerSelected:
  76.                         /*
  77.                          * This is a normal container. Set the
  78.                          * "to" button to open/save, but leave the
  79.                          * "cc" button disabled.
  80.                          */
  81.                         enableToButton = TRUE;
  82.                         toStringIndex =
  83.                             (AOM.optKeyDown == 0)
  84.                                 ? kAOMOpenButtonString
  85.                                 : kAOMSaveButtonString;
  86.                         break;
  87.                     case kSDPRecordSelected:
  88.                     case kSDPRecordAliasSelected:
  89.                         /*
  90.                          * This is a normal selection. The "to"
  91.                          * button should read "To" or "Save"
  92.                          */
  93.                         enableToButton = TRUE;
  94.                         enableCCButton = TRUE;
  95.                         toStringIndex =
  96.                             (AOM.optKeyDown == 0)
  97.                                 ? kAOMToButtonString
  98.                                 : kAOMSaveButtonString;
  99.                         break;
  100.                     }
  101.                 }
  102.                 break;
  103.             case kAOMEnableFindBit:
  104.                 /*
  105.                  * The find panel has three states:
  106.                  *    -- enter find criterion
  107.                  *    -- finding
  108.                  *    -- found data, allowselection
  109.                  */
  110.                 status = SDPGetFindPanelState(AOM.findPanel, &findState);
  111.                 LOG(status, "\pSDPGetFindPanelState");
  112.                 if (status == noErr) {
  113.                     if ((findState & kSDPItemIsSelectedMask) != 0) {
  114.                         /*
  115.                          * The user has selected an item. If we are
  116.                          * currently searching, set the "to" button to
  117.                          * "stop", otherwise set it to "to" or "save"
  118.                          * depending on the state of the option key.
  119.                          * Since we have a selection, enable the cc button.
  120.                          */
  121.                         enableToButton = TRUE;
  122.                         enableCCButton = TRUE;
  123.                         toStringIndex =
  124.                             (FINDING)
  125.                                 ? kAOMStopButtonString
  126.                                 : (AOM.optKeyDown == 0)
  127.                                     ? kAOMToButtonString
  128.                                     : kAOMSaveButtonString;
  129.                     }
  130.                     else if ((findState & kSDPFindTextExistsMask) != 0) {
  131.                         /*
  132.                          * Nothing has been selected, but the user has
  133.                          * specified a search string. If we are
  134.                          * currently searching, set the "to" button
  135.                          * to "stop", else, set it to "Find"
  136.                          */
  137.                         enableToButton = TRUE;
  138.                         toStringIndex =
  139.                             (FINDING)
  140.                                 ? kAOMStopButtonString
  141.                                 : kAOMFindButtonString;
  142.                     }
  143.                     else {
  144.                         /*
  145.                          * Nothing has been setup yet. Set the
  146.                          * "to" string to "Find" and leave it
  147.                          * disabled.
  148.                          */
  149.                         toStringIndex = kAOMFindButtonString;
  150.                     }            
  151.                 }
  152.                 break;
  153. #ifdef ENABLE_TYPEIN
  154.             case kAOMEnableTypeInBit:
  155.                 if ((**AOM.typeInAddress).teLength > 0) {
  156.                     /*
  157.                      * The user has typed something. The "to"
  158.                      * button should read "To" or "Save"
  159.                      */
  160.                     enableToButton = TRUE;
  161.                     enableCCButton = TRUE;
  162.                     toStringIndex =
  163.                         (AOM.optKeyDown == 0)
  164.                             ? kAOMToButtonString
  165.                             : kAOMSaveButtonString;
  166.                 }
  167.                 break;
  168. #endif
  169.             }
  170.             /*
  171.              * The SDP stuff trashed the font info.
  172.              */
  173.             _AOMSetFont(aomPtr, kAOMLabelFontStyle);
  174.             if (AOM.toButton != NULL) {
  175.                 if (toStringIndex != AOM.toButtonString) {
  176.                     AOM.toButtonString = toStringIndex;
  177.                     GetIndString(title, AOM.stringsResID, toStringIndex);
  178.                     SetCTitle(AOM.toButton, title);
  179.                 }
  180.                 if (enableToButton != AOM.enableToButton) {
  181.                     AOM.enableToButton = enableToButton;
  182.                     HiliteControl(
  183.                         AOM.toButton,
  184.                         (enableToButton) ? kActiveControl : kInactiveControl
  185.                     );
  186.                     _AOMDrawDefaultButtonOutline(AOM.toButton, AOM.isTarget);
  187.                 }
  188.             }
  189.             if (AOM.ccButton != NULL) {
  190.                 if (ccStringIndex != AOM.ccButtonString) {
  191.                     AOM.ccButtonString = ccStringIndex;
  192.                     GetIndString(title, AOM.stringsResID, ccStringIndex);
  193.                     SetCTitle(AOM.ccButton, title);
  194.                 }
  195.                 if (enableCCButton != AOM.enableCCButton) {
  196.                     AOM.enableCCButton = enableCCButton;
  197.                     HiliteControl(
  198.                         AOM.ccButton,
  199.                         (enableCCButton) ? kActiveControl : kInactiveControl
  200.                     );
  201.                 }
  202.             }
  203.         }
  204.         AOM.enableToButton = enableToButton;
  205.         AOM.buttonUpdateNeeded = FALSE;
  206.         _AOMRestoreState(&saveState);
  207. }
  208.  
  209.